#include <iostream>
#include <memory>
#include <string>

#include "AsyncWorker.hpp"
#include "Client_Connection.hpp"
#include "Common/UUIDHelper.hpp"
#include "Message.pb.h"
#include "client_channel.hpp"
class Init
{
    public:
        Init()
        {
            fmtlog::setLogLevel(fmtlog::DBG);
            fmtlog::setHeaderPattern("{s} \t| {t} \t| {l} \t| {YmdHMS} \t| {g} \t| \n\t:");
            fmtlog::startPollingThread(12);
        }
};
int main() {
    Init _____DONT_USE_ME__ONLY_INIT_LOG_____;
    MY_MQ::AsyncWorker::self_ptr       AsWoker = std::make_shared<MY_MQ::AsyncWorker>();
    MY_MQ::Client_Connection::self_ptr conn = std::make_shared<MY_MQ::Client_Connection>("127.0.0.1", 8888, AsWoker);
    MY_MQ::ClientChannel::self_ptr     channel = conn->openChannel();
    google::protobuf::Map<std::string, std::string> tmp_map;
    channel->declareExchange("exchange1", MQ_Protobuf::ExchangeType::TOPIC, 1, false, tmp_map);
    channel->DeclareQueue("queue1", 1, false, false, tmp_map);
    channel->QueueBind("exchange1", "queue1", "queue1");
    channel->QueueBind("exchange1", "queue2", "new.music.#");
    
    std::cout<<"开始发布消息\n";
    for (int i = 0; i < 10; i++) {
        MQ_Protobuf::BasicProperties bp;
        bp.set_id(MY_MQ::UUIDHelper::uuidWithShuffledMAC());
        bp.set_routing_key("queue1");
        bp.set_delivery_mode(MQ_Protobuf::DeliveryMode::DURABLE);
        channel->basicPublish("exchange1", &bp, "hello world"+ std::to_string(i));
    }
    MQ_Protobuf::BasicProperties bp;
    bp.set_id(MY_MQ::UUIDHelper::uuidWithShuffledMAC());
    bp.set_routing_key("news.music.pop");
    bp.set_delivery_mode(MQ_Protobuf::DeliveryMode::DURABLE);
    channel->basicPublish("exchange1", &bp, "hello world hello ,MQ");
    bp.set_routing_key("news.sport");
    channel->basicPublish("exchange1", &bp, "hello world hello ,MQ");
    conn->closeChannel(channel);
    return 0;
}
